﻿using System;
class ArrayProcess
{
    private int[] numbers;

    // 构造函数，接收数组长度
    public ArrayProcess(int size)
    {
        numbers = new int[size];
    }

    // 读取用户输入并存入数组
    public void ReadArray()
    {
        Console.WriteLine($"请输入 {numbers.Length} 个整数（每两个数之间请用回车隔开）");
        for (int i = 0; i < numbers.Length; i++)
        {
            numbers[i] = int.Parse(Console.ReadLine());
        }
    }
    //求取最值
    public void ExtrmeOut() {
       //冒泡排序
        int n = numbers.Length;
        for (int i = 0; i < n - 1; i++)
        {
            for (int j = 0; j < n - 1 - i; j++)
            {
                if (numbers[j] > numbers[j + 1])
                {
                    // 交换 numbers[j] 和 numbers[j+1]
                    int temp = numbers[j];
                    numbers[j] = numbers[j + 1];
                    numbers[j + 1] = temp;
                }
            }
        }
        Console.WriteLine($"数组的最小值为{numbers[0]}");
        Console.WriteLine($"数组的最大值为{numbers[n-1]}");
    }

    //求取平均值与数组元素总和
    public void SumAve()
    {
        //冒泡排序
        int n = numbers.Length;
        int sum=0;
        double ave = 0;
        for (int i = 0; i < n; i++)
        {
            sum += numbers[i];

        }
        ave = (double)sum / n;
        Console.WriteLine($"所有数组元素的总和为{sum}");
        Console.WriteLine($"数组元素的平均值为{ave}");
    }
}


class Program
{
    static void Main(string[] args)
    {
        Console.Write("请输入数组的长度：");
        int length = int.Parse(Console.ReadLine());

        // 创建 DataProcessor 对象
        ArrayProcess p = new ArrayProcess(length);

        // 调用 ReadArray 读取数据
        p.ReadArray();
        p.ExtrmeOut();
        p.SumAve();
    }
}

